package com.rdc.qingkou.dto;

import com.rdc.qingkou.Application.MyApplication;
import com.rdc.qingkou.R;
import com.rdc.qingkou.config.URL;
import com.rdc.qingkou.entity.Tag;
import com.rdc.qingkou.entity.User;
import com.rdc.qingkou.utils.MyUtils;
import com.rdc.qingkou.vo.CardAndUserVO;
import com.rdc.qingkou.vo.CardVO;
import com.rdc.qingkou.vo.UserVO;

import java.util.Date;
import java.util.List;


public class CardDTO {

    private int cardId;
    private User user;
    private String voiceUrl;
    private String mediaUrl;
    private String content;
    private List<Tag> tags;
    private Date date;
    private int anonymity;
    private int praise;//当前用户是否对该用户点赞【0为不点赞、1为点赞】
    private boolean mediaType;//类型 true 图片 false 音频
    private boolean subsribeStatus;//当前用户是否对该卡片订阅【true 订阅，false 未订阅】
    private boolean collectionStatus;

    public CardVO transformToCard() {
        CardVO cardVO = new CardVO();
        cardVO.setCardId(cardId);
        cardVO.setCollected(collectionStatus);
        if (content != null) {
            cardVO.setContent(content);
        }
        if (user.getUserId() == MyApplication.getUser().getUserId()) {
            cardVO.setMyCard(true);
        } else {
            cardVO.setMyCard(false);
        }
        if (mediaUrl != null && !mediaUrl.equals("")) {
            if (mediaType) {
                //图片
                cardVO.setImageUrl(URL.HEAD_YUN + mediaUrl);
            } else {
                //视频
                cardVO.setMediaUrl(URL.HEAD_YUN + mediaUrl);
            }
        } else {
            cardVO.setImageUrl(MyUtils.getUriFromDrawableRes(MyApplication.getContext(), R.drawable.imageview_default));
        }
        if (voiceUrl != null && !voiceUrl.equals("")) {
            cardVO.setVoiceUrl(URL.HEAD_YUN + voiceUrl);
        }
        cardVO.setAppreciated(praise == 1);
        return cardVO;
    }


    public CardAndUserVO transformToCardAndUser() {
        CardVO cardVO = transformToCard();
        UserVO userVO = new UserVO();
        if (user.getUserId() == MyApplication.getUser().getUserId()) {
            cardVO.setMyCard(true);
        } else {
            cardVO.setMyCard(false);
        }
        userVO.setSubsribeStatus(subsribeStatus);
        if (user.getNickName() == null || user.getNickName().equals("")) {
            userVO.setNickName("路人甲");
        } else {
            userVO.setNickName(user.getNickName().replace("\"", ""));
        }
        userVO.setUserId(user.getUserId());
        if (user.getImageUrl() != null && !user.getImageUrl().equals("")) {
            if (user.getImageUrl().startsWith("/Qing_kou/")) {
                userVO.setHeadImageUrl("http://120.78.74.103" + user.getImageUrl());
            } else {
                userVO.setHeadImageUrl(URL.HEAD_YUN + user.getImageUrl());
            }
        } else {
            userVO.setHeadImageUrl(MyUtils.getUriFromDrawableRes(MyApplication.getContext(), R.drawable.imageview_default_head));
        }
        if (user.getSignature() == null || user.getSignature().equals("")) {
            userVO.setSignature("这个人很懒，什么也没有写。");
        } else {
            userVO.setSignature(user.getSignature().replace("\"", ""));
        }
        CardAndUserVO cardAndUserVO = new CardAndUserVO();
        cardAndUserVO.setCardVO(cardVO);
        cardAndUserVO.setUserVO(userVO);
        return cardAndUserVO;
    }

    public boolean isCollectionStatus() {
        return collectionStatus;
    }

    public void setCollectionStatus(boolean collectionStatus) {
        this.collectionStatus = collectionStatus;
    }

    public boolean isMediaType() {
        return mediaType;
    }

    public void setMediaType(boolean mediaType) {
        this.mediaType = mediaType;
    }

    public boolean isSubsribeStatus() {
        return subsribeStatus;
    }

    public void setSubsribeStatus(boolean subsribeStatus) {
        this.subsribeStatus = subsribeStatus;
    }

    public Boolean getSubsribeStatus() {
        return subsribeStatus;
    }

    public void setSubsribeStatus(Boolean subsribeStatus) {
        this.subsribeStatus = subsribeStatus;
    }

    public Boolean getMediaType() {
        return mediaType;
    }

    public void setMediaType(Boolean mediaType) {
        this.mediaType = mediaType;
    }

    public int getCardId() {
        return cardId;
    }

    public void setCardId(int cardId) {
        this.cardId = cardId;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getVoiceUrl() {
        return voiceUrl;
    }

    public void setVoiceUrl(String voiceUrl) {
        this.voiceUrl = voiceUrl;
    }

    public String getMediaUrl() {
        return mediaUrl;
    }

    public void setMediaUrl(String mediaUrl) {
        this.mediaUrl = mediaUrl;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public List<Tag> getTags() {
        return tags;
    }

    public void setTags(List<Tag> tags) {
        this.tags = tags;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public int getAnonymity() {
        return anonymity;
    }

    public void setAnonymity(int anonymity) {
        this.anonymity = anonymity;
    }

    public int getPraise() {
        return praise;
    }

    public void setPraise(int praise) {
        this.praise = praise;
    }


}
